<h5>Interfacing the Wiring hardware and Blender/Phyton</h5>
<p>This tutorial introduces the basic interfacing between the Wiring hardware and and Blender/Phyton <a href="http://www.blender.org/">http://www.blender.org/</a>. The brief for the tutorial will be to send  data to the Wiring board, the Wiring board will read the data and turn ON or OFF the board LED accordingly. It assumes the Wiring software and Blender/Phyton are installed and the proper Wiring setup has been previously completed. For more Information on Wiring install check out the <a href="http://wiring.org.co/learning/tutorials/">tutorials</a> about Wiring installation and software setup.</p>
<p>Note: This tutorial have benn prove it using Blender 2.49 which can be downloaded from <a href="http://download.blender.org/release/">here</a> and Phyton 2.5 wich can be downloaded from <a href="http://www.python.org/download/releases/2.5.6/">here</a>.</p>
<h5>Step 1</h5>
<p>Copy and paste the following code on the Wiring editor: Verify your program is free of compiling errors by pressing the Compile/Verify button in the menu bar. Press the Upload button in the menu bar. In case of syntax errors the Wiring environment will print the error messages otherwise it will print the Upload was completed successfully, the uploading process triggers activity in the Rx/Tx LEDs on the Wiring hardware. The new program will start automatically after uploading. Use the Serial Monitor button to watch the data coming from the Wiring board, then close the Serial Monitor again.</p>
<pre>
/**
 * Simple Read/ Blender/Python
 * 
 * Read data from the serial port and turn ON the onboard LED if
 * the character received is an 'a'
 * For the Wiring boards v1 the on-board LED is on pin 48, 
 * on Wiring S the on-board LED is on pin 15.
 */

int data; // to read the char

void setup() {
  Serial.begin(9600);
  pinMode(WLED, OUTPUT);
}

void loop() {
  if(Serial.available()) {      // if data available
    data = Serial.read();       // read data
    if(data == 'H') {           // if value read is character 'a'
      digitalWrite(WLED, HIGH); // turn ON the onboard LED
    } else {
      digitalWrite(WLED, LOW);  // if not turn it OFF
    }
  }
  delay(100); // wait 100ms for next read
}
</pre>
<p>&nbsp;</p>
<h5>Paso 2</h5>
<p>Download PySerial <a href="http://pyserial.sourceforge.net/">here</a>. Uncompress the file and placed the folder &quot;serial&quot; with the other Python libraries for Blender.</p>
<p><b>Windows:</b></p>
<p>Placed the folder &quot;serial&quot; in the folder &quot;.blender/scripts&quot; which us inside the Blender folder.</p>
<p><b>Mac OS X:</b></p>
<p>Turn on hidden files by opening a terminal and running the following two lines:</p>
<pre>
username$ defaults write com.apple.Finder AppleShowAllFiles yes
username$ Killall Finder
</pre>
<p>To turn off the hidden files just do the same again but use &quot;no&quot; instead of &quot;yes&quot;.</p>
<p>Placed the folder &quot;serial&quot; in the folder &quot;.blender/scripts&quot; which us inside the Blender folder.</p>
<p>&nbsp;</p>
<h5>Step 3</h5>
<p>Next step is to setup things in Blender. Setup the interface to &quot;Scripting&quot; mode. </p>
<p><img src="imgs/blender-01.png" width="700" height="423" /></p>
<p>&nbsp;</p>
<h5>Step 4</h5>
<p>Copy the following code in the editor and name it &quot;script.py&quot;.</p>
<pre>
import serial
from time   import sleep
# you will need the name of your serial port
# check in wiring - tools - menu
serialport = serial.Serial('COM2', 9600)

sleep(4)    

while 1:
     serialport.write('H')
     sleep(1)
     serialport.write('L')
     sleep(1)

serialport.close()
</pre>
<p><img src="imgs/blender-05.png" width="489" height="316" /></p>
<h5>Step 5</h5>
<p>Attach an object. Select any object in the scene and click on its logic properties in the &quot;Buttons Window&quot;.</p>
<p>Add an always sensor and link it to the python script. This should mean the python script will be executed when the game engine is running. It should look like this: </p>
<p><img src="imgs/blender-03.png" width="979" height="201" /></p>
<h5>Step 6</h5>
<p>Run the game engine. Click in the '3D Panel' and just press 'P'.</p>
<p>&nbsp;</p>
